package com.mapbased.cc;

import java.io.IOException;
import com.mapbased.wfw.RenderContext;
import com.mapbased.cc.form.FormElement;
import com.mapbased.wfw.Constants;
import java.util.Map;
import com.mapbased.cc.form.TitleFormElement;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 */
public class FreeForm
    extends Form
{
    public void render(RenderContext r)
        throws IOException
    {
        defalutRenderBehavior(r,this.attributes);

        java.io.Writer w=r.getOutputWriter();
        Map m=(Map)r.getRequestMap().get(Constants.Valid_Errors);
        FormElement[] elements=this.getFormElements(r);

        for(int i=0;i < elements.length;i++)
        {
            FormElement fe=elements[i];

            if(fe instanceof TitleFormElement)
            {
                w.write("<label   class=\"label\"  for=\"");
                w.write(fe.getName());
                w.write("\">");

                w.write(fe.getCaption());
                w.write("</label>");

                continue;
            }
            w.write("<span ");
            if(m != null && m.containsKey(fe.getName()))
            {
                w.write("class=\"highlight_true\" ");
            }
            w.write(">");

            String s=fe.getCaption();
            if(s != null && s.length() > 0)
            {
                w.write("<label  class=\"label\" for=\"");
                w.write(fe.getName());
                w.write("\">");
                w.write(s);
                w.write(":");
                w.write("</label>");

            }
            fe.renderInputPart(r);

            w.write("</span>");

        }

        defalutRenderBehavior(r,this.segments);

    }
}
